package com.uhomecp.lambda2;

import com.google.common.collect.Maps;
import com.uhomecp.lambda.lambda7.Employee;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @description: EmployeeTest 01 03 branch_002 01 02 04 05 1
 * @create: 2020-01-15 15:44
 **/
public class EmployeeTest {

    public static List<Employee> generateData() {
        return Arrays.asList(new Employee("Matt", 5000, "New York"),
                new Employee("Steve", 6000, "London"),
                new Employee("Carrie", 10000, "New York"),
                new Employee("Peter", 7000, "New York"),
                new Employee("Alec", 6000, "London"),
                new Employee("Sarah", 8000, "London"),
                new Employee("Rebecca", 4000, "New York"),
                new Employee("Pat", 20000, "New York"),
                new Employee("Tammy", 9000, "New York"),
                new Employee("Fred", 15000, "Tokyo"));
    }

    public static Map<String, Integer> generateMapData() {
        Map<String, Integer> items = Maps.newHashMap();
        items.put("A", 10);
        items.put("B", 20);
        items.put("C", 30);
        items.put("D", 40);
        items.put("E", 50);
        items.put("F", 60);

        return items;
    }

    public static void main(String[] args) {
        List<Employee> results = generateData();

        //打印出名字是Steve的员工信息
        results.stream().filter(employee -> employee.getName().equals("Steve")).forEach(employee -> {
//            if (employee.getName().equals("Steve")){
                System.out.println(employee);
//            }
        });

        System.out.println("---------");

        //找出年薪超过15000的员工
        results.stream().filter(employee -> employee.getSalary() >= 15000).forEach(employee -> System.out.println(employee));

        System.out.println("--->>>>>>----");

        //java8遍历map
        Map<String, Integer> map_ = generateMapData();
        map_.forEach((key, value) -> System.out.println("key:" + key + "," + "value:" + value));

        System.out.println("---->>>>分组>>>-----");
        Map<String, List<Employee>> groupMap = results.stream().collect(Collectors.groupingBy(employee -> employee.getOffice()));
        System.out.println(groupMap);

        System.out.println("---->>>>List转化为Map>>>----");
//        results.stream().
    }
}
